﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Transport
{
    public class HoiDapControl
    {
        transportEntities db;

        public HoiDapControl()
        {
            db = new transportEntities();
        }

        public List<hoi_dap> listAll()
        {
            try
            {
                return db.hoi_dap.ToList();
            }
            catch (Exception)
            {
                return null;
            }
        }

        public bool insert(hoi_dap value)
        {
            try
            {
                DateTime centuryBegin = new DateTime(2000, 1, 1);
                DateTime currentDate = DateTime.Now;

                value.id = (currentDate.Ticks - centuryBegin.Ticks).ToString();
                value.tinh_trang = "0";
                db.hoi_dap.AddObject(value);
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public bool updateStatus(string id, string status)
        {
            try
            {
                hoi_dap st = db.hoi_dap.SingleOrDefault(t => t.id == id);
                st.tinh_trang = status;
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public bool update(hoi_dap value)
        {
            try
            {
                hoi_dap st = db.hoi_dap.SingleOrDefault(t => t.id == value.id);
                st = value;
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public bool delete(string Id)
        {
            try
            {
                hoi_dap st = db.hoi_dap.SingleOrDefault(t => t.id == Id);
                db.hoi_dap.DeleteObject(st);
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}